package exam.controller;

import exam.bean.PaperLevel;
import exam.service.IPaperLevelService;
import exam.utils.Msg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;


@RestController()
@RequestMapping("/PaperLevel")
public class PaperLevelController {
    @Autowired
    IPaperLevelService paperLevelService;
    @ResponseBody
    @GetMapping("/PaperLevelAll")
    public Msg ProjectLevelAll(){
        return Msg.success().add("paperLevel",paperLevelService.selectInfo());
    }

    @ResponseBody
    @GetMapping("/PaperLevelSelect")
    @PreAuthorize("hasAuthority('sys:sysParam:paperLevel:list')")
    public Msg paperLevelSelect(){
        return Msg.success().add("paperLevel",paperLevelService.selectInfo());
    }

    @ResponseBody
    @PostMapping("/PaperLevelInsert")
    @PreAuthorize("hasAuthority('sys:sysParam:paperLevel:add')")
    public Msg paperLevelInsert(@RequestBody  PaperLevel paperLevel){
        int res = paperLevelService.insertInfo(paperLevel);
        return res > 0 ? Msg.success().setMessage("添加成功") : Msg.fail().setMessage("添加失败");
    }

    @ResponseBody
    @PostMapping("/PaperLevelUpdate")
    @PreAuthorize("hasAuthority('sys:sysParam:paperLevel:update')")
    public Msg paperLevelUpdate(@RequestBody PaperLevel paperLevel){
        int res = paperLevelService.updateInfo(paperLevel);
        return res > 0 ? Msg.success().setMessage("修改成功") : Msg.fail().setMessage("修改失败");
    }

    @ResponseBody
    @GetMapping("/PaperLevelDelete")
    @PreAuthorize("hasAuthority('sys:sysParam:paperLevel:delete')")
    public Msg paperLevelDelete(@RequestParam(value = "id") int id){
        int res = paperLevelService.deleteInfo(id);
        return res > 0 ? Msg.success().setMessage("删除成功") : Msg.fail().setMessage("删除失败");
    }

    @ResponseBody
    @GetMapping("/PaperLevelDetail")
    @PreAuthorize("hasAuthority('sys:sysParam:paperLevel:update')")
    public Msg paperLevelDetail(@RequestParam(value = "id") int id){
        Map<String,Object> queryMap =new HashMap<String,Object>();
        queryMap.put("id",id);
        return Msg.success().add("paperLevelInfo",paperLevelService.selectInfoSingle(queryMap));
    }
}
